package com.ruoyi.system.service.impl.smy;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.constant.OrderType;
import com.ruoyi.common.core.domain.smy.MallAdvertis;
import com.ruoyi.common.dto.OptDto;
import com.ruoyi.system.mapper.smy.MallAdvertisMapper;
import com.ruoyi.system.service.smy.IMallAdvertisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Service
public class MallAdvertisServiceImpl implements IMallAdvertisService {

	@Resource
	private MallAdvertisMapper mallAdvertisMapper;

	@Override
	public MallAdvertis selectMallAdvertisById(Long id) {
		return mallAdvertisMapper.selectMallAdvertisById(id);
	}

	@Override
	public List<MallAdvertis> selectMallAdvertisList(MallAdvertis mallAdvertis) {
		return mallAdvertisMapper.selectMallAdvertisList(mallAdvertis);
	}

	@Override
	public int insertMallAdvertis(MallAdvertis mallAdvertis) {
		mallAdvertis.setStatus(1L);
		mallAdvertis.setChannelId(0L);
		mallAdvertis.setChannelLevel(0L);
		mallAdvertis.setSubjectId(0L);
		mallAdvertis.setInnerLinkId(0L);
		mallAdvertis.setInnerLinkType(0L);
		mallAdvertis.setCreateTime(new Date());
		return mallAdvertisMapper.insertMallAdvertis(mallAdvertis);
	}

	@Override
	public int updateMallAdvertis(MallAdvertis mallAdvertis) {
		return mallAdvertisMapper.updateMallAdvertis(mallAdvertis);
	}

	@Override
	public int deleteMallAdvertisByIds(Long[] ids) {
		return mallAdvertisMapper.deleteMallAdvertisByIds(ids);
	}

	@Override
	public int deleteMallAdvertisById(Long id) {
		return mallAdvertisMapper.deleteMallAdvertisById(id);
	}

	@Override
	public void changeAdvertisingStatus(OptDto optDto) {
		MallAdvertis mallAdvertis = mallAdvertisMapper.selectMallAdvertisById(optDto.getLongId());
		if(Objects.nonNull(mallAdvertis)){
			if(StrUtil.equals(OrderType.YES,optDto.getOptType())){
				mallAdvertis.setStatus(2L);
			}
			if(StrUtil.equals(OrderType.NO,optDto.getOptType())){
				mallAdvertis.setStatus(1L);
			}
			mallAdvertisMapper.updateMallAdvertis(mallAdvertis);
		}
	}
}
